package com.example.zhinongbao.view;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.zhinongbao.R;
import com.example.zhinongbao.contract.FriendsContact;
import com.example.zhinongbao.presenter.FriendsPresenter;


public class FriendsFragment extends Fragment implements View.OnClickListener , FriendsContact {
    private View friends_fragment ;
    private ImageButton MyPublishBtn , FriendsToPublishBtn ;
    private TextView FriendsLatest , FriendsConcern ;
    private FriendsPresenter friendsPresenter ;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (friends_fragment == null){
            friends_fragment = inflater.inflate(R.layout.fragment_nongyouquan, container , false);
        }
        friendsPresenter = new FriendsPresenter(this);
        MyPublishBtn = friends_fragment.findViewById(R.id.my_publish_btn) ;
        FriendsLatest = friends_fragment.findViewById(R.id.friends_latest) ;
        FriendsConcern = friends_fragment.findViewById(R.id.friends_concern) ;
        FriendsToPublishBtn = friends_fragment.findViewById(R.id.to_publish_btn) ;

        FriendsLatest.setSelected(true);

        onFriendsMyPublishBtnClick();
        onFriendsLatestClick();
        onFriendsConcernClick();
        onFriendsToPublishBtnClick();

        return friends_fragment ;
    }
    public void onResume(){
        super.onResume();
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.my_publish_btn){
            Toast.makeText(FriendsFragment.this.getContext(), "Clicked", Toast.LENGTH_SHORT).show();
        } else if (v.getId() == R.id.friends_latest) {
            FriendsLatest.setSelected(true);
            FriendsConcern.setSelected(false);
        } else if (v.getId() == R.id.friends_concern) {
            FriendsLatest.setSelected(false);
            FriendsConcern.setSelected(true);
        } else if (v.getId() == R.id.to_publish_btn) {
            Intent intent = new Intent(FriendsFragment.this.getContext() , AddGoodsActivity.class) ;
            startActivity(intent);
        }
    }

    @Override
    public void onFriendsMyPublishBtnClick() {
        MyPublishBtn.setOnClickListener(this);
    }

    @Override
    public void onFriendsLatestClick() {
        FriendsLatest.setOnClickListener(this);
    }

    @Override
    public void onFriendsConcernClick() {
        FriendsConcern.setOnClickListener(this);
    }

    @Override
    public void onFriendsToPublishBtnClick() {
        FriendsToPublishBtn.setOnClickListener(this);
    }
}
